import keras
import numpy as np
import matplotlib.pyplot as plt

# 直接加载keras 模型
model = keras.saving.load_model('model.keras')

# 构建一个满屏的x,y 坐标

number = 10000

x = np.linspace(0,1.0,number)
np.random.shuffle(x)
y = np.linspace(0,1.0,number)
np.random.shuffle(y)

x_tmp = np.array(x,ndmin=2)
y_tmp = np.array(y,ndmin=2)
xy = np.stack((x_tmp,y_tmp),axis=2)[0]

# print(xy)
# 使用加载模型预测
predict_result = model.predict(xy)
z = np.argmax(predict_result,axis=1)
z_tmp = np.array(z,ndmin=2).reshape(-1,1)
xyz = np.concatenate((xy,z_tmp),axis=1)

for i in xyz:
    i[0] = int(i[0] * 100)
    i[1] = int(i[1] * 100)
    i[2] = int(i[2])

xyz = xyz.astype(dtype=np.int32)
print(xyz)
# 定义一个100x100x3黑色区域
rect = np.zeros((101,101,3))
# 为黑色区域涂颜色
for item in xyz:
    if item[2] == 0:
        #红色
        rect[item[0],item[1]][2] = 255
    elif item[2] == 1:
        # 蓝色
        rect[item[0], item[1]][0] = 255

# 用图表方式绘制
plt.imshow(rect)
plt.show()








